package com.jeesite.modules.pt.web;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.pt.entity.PtSetting;
import com.jeesite.modules.pt.service.PtSettingService;

/**
 * 平台参数Controller
 * @author 李寒冰
 * @version 2024-12-10
 */
@Controller
@RequestMapping(value = "${adminPath}/pt/ptSetting")
public class PtSettingController extends BaseController {

	@Autowired
	private PtSettingService ptSettingService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public PtSetting get(String id, boolean isNewRecord) {
		return ptSettingService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("pt:ptSetting:view")
	@RequestMapping(value = {"list", ""})
	public String list(PtSetting ptSetting, Model model) {
		model.addAttribute("list", ptSettingService.findList(ptSetting));
		return "modules/pt/ptSettingForm";
	}

	/**
	 * 查询列表
	 */
	@RequiresPermissions("pt:ptSetting:view")
	@RequestMapping(value = {"listUrl", ""})
	public String listUrl(PtSetting ptSetting, Model model) {
		model.addAttribute("list", ptSettingService.findList(ptSetting));
		return "modules/pt/ptSettingFormUrl";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("pt:ptSetting:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<PtSetting> listData(PtSetting ptSetting, HttpServletRequest request, HttpServletResponse response) {
		ptSetting.setPage(new Page<>(request, response));
		Page<PtSetting> page = ptSettingService.findPage(ptSetting);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("pt:ptSetting:view")
	@RequestMapping(value = "form")
	public String form(PtSetting ptSetting, Model model) {
		model.addAttribute("ptSetting", ptSetting);
		return "modules/pt/ptSettingForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("pt:ptSetting:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated PtSetting ptSetting) {
		ptSettingService.save(ptSetting);
		return renderResult(Global.TRUE, text("保存平台参数成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("pt:ptSetting:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(PtSetting ptSetting) {
		ptSettingService.delete(ptSetting);
		return renderResult(Global.TRUE, text("删除平台参数成功！"));
	}
	
}